from loguru import logger
# class Cache(object):
#
#     def __init__(self):
#         self.data = {}
#
#     def add(self, key, value):
#         self.data[key] = value
#
#     def remove(self, key):
#         self.data.pop(key)
#
#     def show(self):
#         print(self.data)
#
#     def __len__(self):
#         return len(self.data)

#
# cache = Cache()
# cache["name"] = "yuan"
# cache["age"] = 18
# cache.add("name", "yuan")
# cache.add("age",18)
# cache.show()
# cache.remove("age")
# cache.show()
# data = []
# data.append("yuan")
# data.append("rain")
# data.append("alvin")
# data.remove("yuan")
# print(len(cache))
class Cache(object):

    def __init__(self):
        self.__data = {}

    def __getitem__(self, key):
        # self.data[key] = value
        # return self.__data.get(key)
        val = self.__data.get(key)
        if val:
            return val
        else:
            raise KeyError(f"{key}键不存在")

    def __setitem__(self, key, value):
        self.__data[key] = value
        logger.info(f"以及向self.__data添加了{key}和{value}")

    def __delitem__(self, key):
        del self.__data[key]

    def __contains__(self, key):
        return key in self.__data
    # def remove(self, key):
    #     self.data.pop(key)

    # def show(self):
    #     print(self.data)
    #
    # def __len__(self):
    #     return len(self.data)

cache = Cache()
cache["name"] = "yuan"
# cache["age"] = 18
print(cache["name"])

# del cache["name"]
# print(cache["name"])

print("name" in cache)